﻿using System.Windows;
using System.Windows.Controls;
using VisionApp.Startup.ViewModels;

namespace VisionApp.Startup.Helper;

public class ConfigItemTemplateSelector : DataTemplateSelector
{
    public DataTemplate BooleanTemplate { get; set; }
    public DataTemplate StringTemplate { get; set; }
    public DataTemplate NumberTemplate { get; set; }
    public DataTemplate DefaultTemplate { get; set; }

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        if (item is ConfigItemViewModel vm)
        {
            switch (vm.ValueType)
            {
                case "Boolean":
                    return BooleanTemplate;
                case "String":
                    return StringTemplate;
                case "Double":
                case "Int64":
                case "Int32":
                    return NumberTemplate;
                default:
                    return DefaultTemplate;
            }
        }
        return base.SelectTemplate(item, container);
    }
}